//
//  YZMRechargeCell.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/5.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMRechargeCell.h"

@interface YZMRechargeCell()

@property (nonatomic, strong) UIImageView *logoImageView;
@property (nonatomic, strong) UILabel *payNameLabel;
@property (nonatomic, strong) UILabel *hintLabel;
@property (nonatomic, strong) UIImageView *recommendMark;

@end

@implementation YZMRechargeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle: style reuseIdentifier: reuseIdentifier];
    if (self) {
        [self createObjects];
        [self assignConstraints];
        self.accessoryView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"left_arrow"]];
    }
    return self;
}

#pragma mark -- operation

- (void)setPayName:(NSString *)payName{
    
    self.payNameLabel.text = payName;
}

- (void)setPayHint:(NSString *)payHint{
    
    self.hintLabel.text = payHint;
}

- (void)setRecommandFlagShow:(BOOL)recommandFlagShow;
{
    if (self.recommendMark == nil && recommandFlagShow) {
        self.recommendMark = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"icon_recharge_recommend"]];
        [self.contentView addSubview: self.recommendMark];
        [self.recommendMark mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.payNameLabel.mas_trailing).with.offset(10);
            make.centerY.equalTo(self.payNameLabel);
        }];
    }
    self.recommendMark.hidden = !recommandFlagShow;
}


#pragma mark -- ui

- (void)createObjects
{
    self.logoImageView = [[UIImageView alloc] init];
    [self.contentView addSubview: self.logoImageView];
    
    self.payNameLabel = [YZMAppStyle labelWithLargeWhite];
    [self.contentView addSubview: self.payNameLabel];
    
    self.hintLabel = [YZMAppStyle labelWithSmallLightGray];
    [self.contentView addSubview: self.hintLabel];
}

- (void)assignConstraints
{
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).with.offset(PAGECONTENTMARGIN);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(66);
        make.height.mas_equalTo(16);
        
    }];
    
    [self.payNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).with.offset(104);
        make.bottom.equalTo(self.contentView.mas_centerY);
    }];
    
    [self.hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.payNameLabel);
        make.top.equalTo(self.contentView.mas_centerY).with.offset(8);
    }];
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    if (self.logoImageView.image) {
        
        float height = ceilf(66 * self.logoImageView.image.size.height /self.logoImageView.image.size.width);
        [self.logoImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(height);
        }];
    }
}


@end
